﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KpBusiness.Model;
using KpMis.Models;
using KpBusiness.Service;
using WebApp.Utility;

namespace KpMis.Controllers
{ 
    public class CompanyController : Controller
    {
        private CompContext db = new CompContext();

        //
        // GET: /Company/

        public ViewResult Index()
        {
            return View(new CompanyService().GetAllCompanys());
        }

        //
        // GET: /Company/Details/5

        public ViewResult Details(int id)
        {
            Company company = new CompanyService().GetCompany(id);
            return View(company);
        }

        //
        // GET: /Company/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Company/Create

        [HttpPost]
        [ValidateOnlyIncomingValuesAttribute]
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                new CompanyService().SaveCompany(company);
                return RedirectToAction("Index");  
            }

            return View(company);
        }
        
        //
        // GET: /Company/Edit/5
 
        public ActionResult Edit(int id)
        {
            Company company = new CompanyService().GetCompany(id);
            return View(company);
        }

        //
        // POST: /Company/Edit/5

        [HttpPost]
        [ValidateOnlyIncomingValuesAttribute]
        public ActionResult Edit(Company company)
        {
            if (ModelState.IsValid)
            {
                new CompanyService().SaveCompany(company);
                return RedirectToAction("Index");
            }
            return View(company);
        }

       

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}